package com.ruoyi.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ErpWeeklyRecord;
import com.ruoyi.erp.service.IErpWeeklyRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 周报分享人列表Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/erp/weeklyRecord")
public class ErpWeeklyRecordController extends BaseController
{
    @Autowired
    private IErpWeeklyRecordService erpWeeklyRecordService;

    /**
     * 查询周报分享人列表列表
     */
    @PreAuthorize("@ss.hasPermi('erp:weeklyRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpWeeklyRecord erpWeeklyRecord)
    {
        startPage();
        List<ErpWeeklyRecord> list = erpWeeklyRecordService.selectErpWeeklyRecordList(erpWeeklyRecord);
        return getDataTable(list);
    }

    /**
     * 导出周报分享人列表列表
     */
    @PreAuthorize("@ss.hasPermi('erp:weeklyRecord:export')")
    @Log(title = "周报分享人列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpWeeklyRecord erpWeeklyRecord)
    {
        List<ErpWeeklyRecord> list = erpWeeklyRecordService.selectErpWeeklyRecordList(erpWeeklyRecord);
        ExcelUtil<ErpWeeklyRecord> util = new ExcelUtil<ErpWeeklyRecord>(ErpWeeklyRecord.class);
        util.exportExcel(response, list, "周报分享人列表数据");
    }

    /**
     * 获取周报分享人列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:weeklyRecord:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(erpWeeklyRecordService.selectErpWeeklyRecordByUserId(userId));
    }

    /**
     * 新增周报分享人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:weeklyRecord:add')")
    @Log(title = "周报分享人列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpWeeklyRecord erpWeeklyRecord)
    {
        return toAjax(erpWeeklyRecordService.insertErpWeeklyRecord(erpWeeklyRecord));
    }

    /**
     * 修改周报分享人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:weeklyRecord:edit')")
    @Log(title = "周报分享人列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpWeeklyRecord erpWeeklyRecord)
    {
        return toAjax(erpWeeklyRecordService.updateErpWeeklyRecord(erpWeeklyRecord));
    }

    /**
     * 删除周报分享人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:weeklyRecord:remove')")
    @Log(title = "周报分享人列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(erpWeeklyRecordService.deleteErpWeeklyRecordByUserIds(userIds));
    }

    /**
     * 获取分享人列表
     * @param erpWeeklyRecord
     * @return
     */
    @PostMapping("getErpWeeklyRecordList")
    public AjaxResult getErpWeeklyRecordList(@RequestBody ErpWeeklyRecord erpWeeklyRecord){
        return AjaxResult.success(erpWeeklyRecordService.getErpWeeklyRecordList(erpWeeklyRecord));
    }
}
